package com.atguigu.commonutils.result;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

/**
 * 分页
 **/
@Slf4j
public class PageUtils {

    public static void startPage(Map<String, Object> map) {
        JSONObject json = new JSONObject(map);
        int pageNum = json.getIntValue("currentPage");
        int pageSize = json.getIntValue("pageSize");
        PageHelper.startPage(pageNum, pageSize);
    }

   /* public static <T> PageResult<T> getMapPageResult(Map<String, Object> params, List<T> maps) {
//        startPage(params);
        PageInfo<T> pageInfo = new PageInfo<>(maps);
        return new PageResult<>(pageInfo);
    }

    public static <T> BaseResult getBaseResult(PageResult<T> mapPageResult) {
        PageResult<T> list = null;
        try {
            list = mapPageResult;
        } catch (Exception e) {
            log.error("查询失败", e);
            throw e;
        }
        return BaseResult.success().setData(list);
    }*/
}
